<%@ page import='java.util.*,com.db.tracker.util.*'%>
<HEAD>
<TITLE>Select Window</TITLE>
<link type="text/css" rel="stylesheet" href="styles/tracker_style.css">
</HEAD>
<script>
function setSelect(){
	val = document.sel_Form.Mtp_select.value;
	if(val==""){
		//Do nothing
	}else{
		parent.opener.setText(document.sel_Form.Mtp_select.value);
		window.close();
	}
}
function SubmitPage(){
	value = document.sel_Form.COLVALUE.value;
	if(trim(value)==""){
		alert("Please enter a value to be added");
	}else{
		document.sel_Form.ADDTOLIST.value='YES';
		document.sel_Form.submit();
	}
}
function trim(sString) {
   sTrimmedString = "";
   if (sString != "") {
      var iStart = 0;
      var iEnd = sString.length - 1;
   	  var sWhitespace = "   ";
	while (sWhitespace.indexOf(sString.charAt(iStart)) != -1) {
         iStart++;
         if (iStart > iEnd)
            break;
      }
	if (iStart <= iEnd) {
         while (sWhitespace.indexOf(sString.charAt(iEnd)) != -1)
            iEnd--;
         sTrimmedString = sString.substring(iStart,++iEnd);
    }
  }
   return sTrimmedString;
}
</script>
<%
String name = (String)request.getParameter("COLNAME");
String addstr = (String)request.getParameter("ADDTOLIST");
DBUtil dbutil = new DBUtil(getServletContext());

if("YES".equals(addstr)){
	String value = (String)request.getParameter("COLVALUE");
	dbutil.addList(name,value);
}
ArrayList list = dbutil.getList(name);
%>
<form name='sel_Form' action='selectWindow.jsp'>
<center>
<table cellspacing=1 style='BORDER:solid 1px #000000'>
<tr><td colspan=2 bgcolor='#000077'>&nbsp;</td></tr>
<tr><td valign='center'class='bodyblue' bgcolor='#EFEFEF'><b>Select a value</b></td>
<td align='left' bgcolor='#EFEFEF'>
<select name='Mtp_select' size='5' onclick='setSelect()' class=bodyblue>
	<%
	if(list.size()==0){
		%><option>-- No values --</option><%
	}
	for(int i=0;i<list.size();i++){
		String value = (String)list.get(i);%>
	<option name='opt1' value='<%=value%>'><%=value%></option>
	<%}%>
</select>
</td></tr>
<tr><td  bgcolor='#EFEFEF' class=bodyblue><b>Add to List</b></td>
<td bgcolor='#EFEFEF'><INPUT name='COLVALUE' value='' class=bodyblue>&nbsp;<INPUT type='button' class='whitebutton' value='Add' onclick='SubmitPage()'></td></tr>
<tr><td colspan=2 bgcolor='#000077'>&nbsp;</td></tr>
<input type='hidden' name='COLNAME' value='<%=name%>'>
<input type='hidden' name='ADDTOLIST' value=''>
</table>
</center>
</form>